diff --git a/src/www/ui/admin-license-file.php b/src/www/ui/admin-license-file.php index 49067410..a1ebf125 100644 --- a/src/www/ui/admin-license-file.php +++ b/src/www/ui/admin-license-file.php @@ -1,509 +1,508 @@ Name = "admin_license"; $this->Title = TITLE_admin_license_file; $this->MenuList = "Admin::License Admin"; $this->DBaccess = PLUGIN_DB_ADMIN; parent::__construct(); $this->dbManager = $GLOBALS['container']->get('db.manager'); } /** * \brief Customize submenus. */ function RegisterMenus() { if ($this->State != PLUGIN_STATE_READY) { return(0); } $URL = $this->Name."&add=y"; $text = _("Add new license"); menu_insert("Main::".$this->MenuList."::Add License",0, $URL, $text); $URL = $this->Name; $text = _("Select license family"); menu_insert("Main::".$this->MenuList."::Select License",0, $URL, $text); } public function Output() { $V = ""; // menu_to_1html(menu_find($this->Name, $MenuDepth),0); $errorstr = "License not added"; // update the db if (@$_POST["updateit"]) { $resultstr = $this->Updatedb($_POST); $V .= $resultstr; if (strstr($resultstr, $errorstr)) { $V .= $this->Updatefm(0); } else { $V .= $this->Inputfm(); } return $V; } if (@$_REQUEST['add'] == 'y') { $V .= $this->Updatefm(0); return $V; } // Add new rec to db if (@$_POST["addit"]) { $resultstr = $this->Adddb($_POST); $V .= $resultstr; if (strstr($resultstr, $errorstr)) { $V .= $this->Updatefm(0); } else { $V .= $this->Inputfm(); } return $V; } // bring up the update form $rf_pk = @$_REQUEST['rf_pk']; if ($rf_pk) { $V .= $this->Updatefm($rf_pk); return $V; } $V .= $this->Inputfm(); if (@$_POST["req_shortname"]) $V .= $this->LicenseList($_POST["req_shortname"], $_POST["req_marydone"]); return $V; } /** * \brief Build the input form * * \return The input form as a string */ function Inputfm() { $V = "
\n"; $V.= "$text | "; $text = _("Checked"); $ob .= "$text | "; $text = _("Shortname"); $ob .= "$text | "; $text = _("Fullname"); $ob .= "$text | "; $text = _("Text"); $ob .= "$text | "; $text = _("URL"); $ob .= "$text | "; $ob .= "
---|---|---|---|---|---|
".
"![]() | ";
$marydone = ($row['marydone'] == 't') ? "Yes" : "No";
$text = _("$marydone");
$ob .= "$text | "; $ob .= "$row[rf_shortname] | "; $ob .= "$row[rf_fullname] | "; $vetext = htmlspecialchars($row['rf_text']); $ob .= ""; $ob .= " | $row[rf_url] | "; $ob .= "
"; } if ($this->isShortnameBlocked($rfId,$shortname,$text)) { $text = _("ERROR: The shortname or license text already exist in the license list. License not added."); return "$text
"; } $md5term = (empty($text) || stristr($text, "License by Nomos")) ? 'null' : 'md5($10)'; $sql = "UPDATE license_ref SET rf_active=$2, marydone=$3, rf_shortname=$4, rf_fullname=$5, rf_url=$6, rf_notes=$7, rf_text_updatable=$8, rf_detector_type=$9, rf_text=$10, rf_md5=$md5term, rf_risk=$11 WHERE rf_pk=$1"; $params = array($rfId, $_POST['rf_active'],$_POST['marydone'],$shortname,$fullname, $url,$notes,$_POST['rf_text_updatable'],$_POST['rf_detector_type'],$text, $riskLvl); $this->dbManager->prepare($stmt=__METHOD__.".$md5term", $sql); $this->dbManager->freeResult($this->dbManager->execute($stmt,$params)); $parentMap = new LicenseMap($this->dbManager, 0, LicenseMap::CONCLUSION); $parentLicenses = $parentMap->getTopLevelLicenseRefs(); if(array_key_exists($parent, $parentLicenses) && $parent!=$parentMap->getProjectedId($rfId)) { $stmtDel = __METHOD__.'.deleteFromMap'; $this->dbManager->prepare($stmtDel,'DELETE FROM license_map WHERE rf_fk=$1 AND usage=$2'); $this->dbManager->execute($stmtDel,array($rfId, LicenseMap::CONCLUSION)); $this->dbManager->insertTableRow('license_map', array('rf_fk'=>$rfId,'rf_parent'=>$parent,'usage'=>LicenseMap::CONCLUSION)); } $reportMap = new LicenseMap($this->dbManager, 0, LicenseMap::REPORT); $reportLicenses = $parentMap->getTopLevelLicenseRefs(); if(array_key_exists($report, $reportLicenses) && $report!=$reportMap->getProjectedId($rfId)) { $stmtDel = __METHOD__.'.deleteFromMap'; $this->dbManager->prepare($stmtDel,'DELETE FROM license_map WHERE rf_fk=$1 AND usage=$2'); $this->dbManager->execute($stmtDel,array($rfId, LicenseMap::REPORT)); $this->dbManager->insertTableRow('license_map', array('rf_fk'=>$rfId,'rf_parent'=>$report,'usage'=>LicenseMap::REPORT)); } $ob = "License $_POST[rf_shortname] updated.
"; return $ob; } /** * \brief Add a new license_ref to the database * * \return An add status string */ function Adddb() { $rf_shortname = trim($_POST['rf_shortname']); $rf_fullname = trim($_POST['rf_fullname']); $rf_url = $_POST['rf_url']; $rf_notes = $_POST['rf_notes']; $rf_text = trim($_POST['rf_text']); $parent = $_POST['rf_parent']; $report = $_POST['rf_report']; $riskLvl = intval($_POST['risk_level']); if (empty($rf_shortname)) { $text = _("ERROR: The license shortname is empty."); return "$text
"; } if ($this->isShortnameBlocked(0,$rf_shortname,$rf_text)) { $text = _("ERROR: The shortname or license text already exist in the license list. License not added."); return "$text
"; } $md5term = (empty($rf_text) || stristr($rf_text, "License by Nomos")) ? 'null' : "md5('$rf_text')"; $stmt = __METHOD__.'.rf'; $sql = "INSERT into license_ref ( rf_active, marydone, rf_shortname, rf_fullname, rf_url, rf_notes, rf_md5, rf_text, rf_text_updatable, rf_detector_type, rf_risk) VALUES ( $1, $2, $3, $4, $5, $6, $md5term, $7, $8, $9, $10) RETURNING rf_pk"; $this->dbManager->prepare($stmt,$sql); $res = $this->dbManager->execute($stmt,array($_POST['rf_active'],$_POST['marydone'],$rf_shortname,$rf_fullname, $rf_url, $rf_notes, $rf_text,$_POST['rf_text_updatable'], $_POST['rf_detector_type'], $riskLvl)); $row = $this->dbManager->fetchArray($res); $rfId = $row['rf_pk']; $parentMap = new LicenseMap($this->dbManager, 0, LicenseMap::CONCLUSION); $parentLicenses = $parentMap->getTopLevelLicenseRefs(); if(array_key_exists($parent, $parentLicenses)) { $this->dbManager->insertTableRow('license_map', array('rf_fk'=>$rfId,'rf_parent'=>$parent,'usage'=>LicenseMap::CONCLUSION)); } $reportMap = new LicenseMap($this->dbManager, 0, LicenseMap::REPORT); $reportLicenses = $reportMap->getTopLevelLicenseRefs(); if(array_key_exists($report, $reportLicenses)) { $this->dbManager->insertTableRow('license_map', array('rf_fk'=>$rfId,'rf_parent'=>$report,'usage'=>LicenseMap::REPORT)); } $ob = "License $_POST[rf_shortname] (id=$rfId) added.
"; return $ob; } /** * \brief get an array of family names based on the * * \return an array of family names based on the * license_ref.shortname. * A family name is the name before most punctuation. * * \example the family name of "GPL V2" is "GPL" */ function FamilyNames() { $familynamearray = array(); $Shortnamearray = DB2KeyValArray("license_ref", "rf_pk", "rf_shortname", " order by rf_shortname"); // truncate each name to the family name foreach ($Shortnamearray as $shortname) { // start with exceptions if (($shortname == "No_license_found") || ($shortname == "Unknown license")) { $familynamearray[$shortname] = $shortname; } else { $tok = strtok($shortname, " _-([/"); $familynamearray[$tok] = $tok; } } return ($familynamearray); } } $NewPlugin = new admin_license_file;